package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.MaterialRequestDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 文件上传
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_picture")
    public ResponseResult upload(MultipartFile multipartFile) throws IOException {
        //1.接收参数
        //2.调用service
        //3.响应数据
        return wmMaterialService.upload(multipartFile);
    }

    /**
     * 分页查询
     */
    @PostMapping("/list")
    public PageResponseResult list(@RequestBody MaterialRequestDto materialRequestDto){
        return wmMaterialService.list(materialRequestDto);
    }

    /**
     * 取消收藏
     */
    @GetMapping("/collect/{id}")
    public ResponseResult colleat(@PathVariable("id") Integer id ){
        //1.接收参数
        //2.调service
        //3.响应结果
        return wmMaterialService.colleat(id);
    }

    /**
     * 取消收藏
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable("id") Integer id ){
        //1.接收参数
        //2.调service
        //3.响应结果
        return wmMaterialService.cancelcCollect(id);
    }

    /**
     * 根据ID删除素材
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult del(@PathVariable("id") Integer id){
        //1.接收参数
        //2.调用service
        //3.响应结果
        return wmMaterialService.del(id);
    }
}
